using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Impact.Model.Objects
{
	/// <summary>
	/// Strongly-typed collection for the ArticleComment class.
	/// </summary>
    [Serializable]
	public partial class ArticleCommentCollection : ActiveList<ArticleComment, ArticleCommentCollection>
	{	   
		public ArticleCommentCollection() {}
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the impact_ArticleComments table.
	/// </summary>
	[Serializable]
	public partial class ArticleComment : ActiveRecord<ArticleComment>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public ArticleComment()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public ArticleComment(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public ArticleComment(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public ArticleComment(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("impact_ArticleComments", TableType.Table, DataService.GetInstance("ImpactProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCommentId = new TableSchema.TableColumn(schema);
				colvarCommentId.ColumnName = "CommentId";
				colvarCommentId.DataType = DbType.Int32;
				colvarCommentId.MaxLength = 0;
				colvarCommentId.AutoIncrement = true;
				colvarCommentId.IsNullable = false;
				colvarCommentId.IsPrimaryKey = true;
				colvarCommentId.IsForeignKey = false;
				colvarCommentId.IsReadOnly = false;
				colvarCommentId.DefaultSetting = @"";
				colvarCommentId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCommentId);
				
				TableSchema.TableColumn colvarArticleId = new TableSchema.TableColumn(schema);
				colvarArticleId.ColumnName = "ArticleId";
				colvarArticleId.DataType = DbType.Int32;
				colvarArticleId.MaxLength = 0;
				colvarArticleId.AutoIncrement = false;
				colvarArticleId.IsNullable = false;
				colvarArticleId.IsPrimaryKey = false;
				colvarArticleId.IsForeignKey = true;
				colvarArticleId.IsReadOnly = false;
				colvarArticleId.DefaultSetting = @"";
				
					colvarArticleId.ForeignKeyTableName = "impact_Articles";
				schema.Columns.Add(colvarArticleId);
				
				TableSchema.TableColumn colvarAuthor = new TableSchema.TableColumn(schema);
				colvarAuthor.ColumnName = "Author";
				colvarAuthor.DataType = DbType.AnsiString;
				colvarAuthor.MaxLength = 255;
				colvarAuthor.AutoIncrement = false;
				colvarAuthor.IsNullable = false;
				colvarAuthor.IsPrimaryKey = false;
				colvarAuthor.IsForeignKey = false;
				colvarAuthor.IsReadOnly = false;
				colvarAuthor.DefaultSetting = @"";
				colvarAuthor.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAuthor);
				
				TableSchema.TableColumn colvarAuthorUrl = new TableSchema.TableColumn(schema);
				colvarAuthorUrl.ColumnName = "AuthorUrl";
				colvarAuthorUrl.DataType = DbType.AnsiString;
				colvarAuthorUrl.MaxLength = 255;
				colvarAuthorUrl.AutoIncrement = false;
				colvarAuthorUrl.IsNullable = true;
				colvarAuthorUrl.IsPrimaryKey = false;
				colvarAuthorUrl.IsForeignKey = false;
				colvarAuthorUrl.IsReadOnly = false;
				colvarAuthorUrl.DefaultSetting = @"";
				colvarAuthorUrl.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAuthorUrl);
				
				TableSchema.TableColumn colvarBody = new TableSchema.TableColumn(schema);
				colvarBody.ColumnName = "Body";
				colvarBody.DataType = DbType.AnsiString;
				colvarBody.MaxLength = 2147483647;
				colvarBody.AutoIncrement = false;
				colvarBody.IsNullable = true;
				colvarBody.IsPrimaryKey = false;
				colvarBody.IsForeignKey = false;
				colvarBody.IsReadOnly = false;
				colvarBody.DefaultSetting = @"";
				colvarBody.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBody);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = false;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				colvarCreatedOn.DefaultSetting = @"";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = false;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["ImpactProvider"].AddSchema("impact_ArticleComments",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("CommentId")]
		[Bindable(true)]
		public int CommentId 
		{
			get { return GetColumnValue<int>(Columns.CommentId); }
			set { SetColumnValue(Columns.CommentId, value); }
		}
		  
		[XmlAttribute("ArticleId")]
		[Bindable(true)]
		public int ArticleId 
		{
			get { return GetColumnValue<int>(Columns.ArticleId); }
			set { SetColumnValue(Columns.ArticleId, value); }
		}
		  
		[XmlAttribute("Author")]
		[Bindable(true)]
		public string Author 
		{
			get { return GetColumnValue<string>(Columns.Author); }
			set { SetColumnValue(Columns.Author, value); }
		}
		  
		[XmlAttribute("AuthorUrl")]
		[Bindable(true)]
		public string AuthorUrl 
		{
			get { return GetColumnValue<string>(Columns.AuthorUrl); }
			set { SetColumnValue(Columns.AuthorUrl, value); }
		}
		  
		[XmlAttribute("Body")]
		[Bindable(true)]
		public string Body 
		{
			get { return GetColumnValue<string>(Columns.Body); }
			set { SetColumnValue(Columns.Body, value); }
		}
		  
		[XmlAttribute("CreatedOn")]
		[Bindable(true)]
		public DateTime CreatedOn 
		{
			get { return GetColumnValue<DateTime>(Columns.CreatedOn); }
			set { SetColumnValue(Columns.CreatedOn, value); }
		}
		  
		[XmlAttribute("CreatedBy")]
		[Bindable(true)]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }
			set { SetColumnValue(Columns.CreatedBy, value); }
		}
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Article ActiveRecord object related to this ArticleComment
		/// 
		/// </summary>
		public Impact.Model.Objects.Article Article
		{
			get { return Impact.Model.Objects.Article.FetchByID(this.ArticleId); }
			set { SetColumnValue("ArticleId", value.ArticleId); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varArticleId,string varAuthor,string varAuthorUrl,string varBody,DateTime varCreatedOn,string varCreatedBy)
		{
			ArticleComment item = new ArticleComment();
			
			item.ArticleId = varArticleId;
			
			item.Author = varAuthor;
			
			item.AuthorUrl = varAuthorUrl;
			
			item.Body = varBody;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varCommentId,int varArticleId,string varAuthor,string varAuthorUrl,string varBody,DateTime varCreatedOn,string varCreatedBy)
		{
			ArticleComment item = new ArticleComment();
			
				item.CommentId = varCommentId;
			
				item.ArticleId = varArticleId;
			
				item.Author = varAuthor;
			
				item.AuthorUrl = varAuthorUrl;
			
				item.Body = varBody;
			
				item.CreatedOn = varCreatedOn;
			
				item.CreatedBy = varCreatedBy;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn CommentIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ArticleIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn AuthorColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn AuthorUrlColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn BodyColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CommentId = @"CommentId";
			 public static string ArticleId = @"ArticleId";
			 public static string Author = @"Author";
			 public static string AuthorUrl = @"AuthorUrl";
			 public static string Body = @"Body";
			 public static string CreatedOn = @"CreatedOn";
			 public static string CreatedBy = @"CreatedBy";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
